/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mx.generarhorario.itschapala.dao;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import mx.generarhorario.itschapala.modelo.Materia;

/**
 *
 * @author RaygozaL
 */
@Stateless
public class MateriaDao extends AbstractDao<Materia> implements MateriaDaoLocal {
    @PersistenceContext(unitName = "generarHorario-ejbPU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public MateriaDao() {
        super(Materia.class);
    }
    
    
    public boolean findDuplicity(Materia materia) {
      
        Query q=em.createNamedQuery("Materia.findDuplicity");
        
        q.setParameter("nombre", materia.getNombre());
        
        return !q.getResultList().isEmpty();
    }
    
}
